package jmine.tec.rpc.server.representation;

import java.util.List;

import jmine.tec.rpc.server.representation.representers.reflection.PropertyRepresenter;
import jmine.tec.rpc.server.representation.representers.reflection.ReflectionRepresenter;

/**
 * FallbackRepresenterFactory que devolve sempre um ReflectionRepresenter, útil para beans em geral.
 * 
 * @author lundberg
 */
public class ReflectionFallbackRepresenterFactory implements FallbackRepresenterFactory {

    private List<? extends PropertyRepresenter> propertyRepresenters;

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    public <R, E> Representer<R, E> create(Class<R> representationClass, Class<E> representedClass) {
        ReflectionRepresenter<R, E> representer = new ReflectionRepresenter<R, E>(representationClass, representedClass);
        representer.setDefaultRepresenters((List<? extends PropertyRepresenter<R, E>>) this.propertyRepresenters);
        return representer;
    }

    /**
     * @param factory the factory to set
     */
    public void setFactory(RepresentationFactory factory) {
    }

    /**
     * @param propertyRepresenters the propertyRepresenters to set
     */
    public void setPropertyRepresenters(List<PropertyRepresenter> propertyRepresenters) {
        this.propertyRepresenters = propertyRepresenters;
    }
}
